<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>2.选择排序</title>
</head>
<body>
    
</body>
<script>
    let array = [2,31,21,441,2,41,23,1,1,0,2,14,1,21]

    let insertSort = function (array) {
        let arrayLength = array.length
        for(let i=0;i<arrayLength;i++) {
            let minIndex = i
            for(let j = i+1;j<arrayLength;j++){
                if(array[j] < array[minIndex]) {
                    minIndex = j
                }
            }
            if(i!==minIndex){
                let temp = array[i]
                array[i] = array[minIndex]
                array[minIndex] = temp
            }
        }
    }

    insertSort(array)
    console.log('选择排序之后的结果:', array)
</script>
</html> 